const baseUrl = "https://api.lifves.com/magazine";

// 搜索
const search = (key) => {
    let list = [],
        data_list = JSON.parse(GET(`${baseUrl}/search/?keyword=${encodeURI(key)}`)).data_list;
    for(var i in data_list) {
        list.push({
            name: `${data_list[i].title}`,
            author: `${data_list[i].qishu}`,
            cover: `${data_list[i].img}`,
            detail: `${baseUrl}/book?mag_id=${data_list[i].mag_id}&qishu=${encodeURI(data_list[i].qishu)}`
        });
    }
    return JSON.stringify(list);
};

// 详情
const detail = (url) => {
    let data_list = JSON.parse(GET(url)).data_list;
    let book = {
        status: `连载`,
        update: `${data_list.qishu}`,
        lastChapter: `${data_list.title}${data_list.qishu}`,
        catalog: `${url}`,
    };
    return JSON.stringify(book);
};

// 目录
const catalog = (url) => {
    let list = [],
        data_list = JSON.parse(GET(url)).data_list.ml;
    for(var i in data_list) {
        let ml_list = data_list[i].list;
        for(var j in ml_list) {
            list.push({
                name: `${ml_list[j].title}`,
                url: `${baseUrl}/read?read_id=${ml_list[j].read_id}`,
                vip: false
            });
        }
    }
    return JSON.stringify(list);
};

// 章节
const chapter = (url) => {
    return JSON.parse(GET(url)).data_list.content;
};

var bookSource = JSON.stringify({
    name: "期刊杂志",
    url: "qk.lifves.com",
    version: 100,
});